home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / VideoToolboxSources / GetClicks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-10  |  2.1 KB  |  52 lines  |  [TEXT/CWIE]

  1. /*
  2. GetClicks.c
  3. waits for a mouse click, and then counts clicks (e.g. double-click, triple-click). Each
  4. click must arrive within the allowed double-click time of the previous,
  5. as set in the Control Panel. Returns the number of clicks, 1 or more.
  6. Calls PrintfExit if the user hits Command-period.
  7. Calls SndStop1() immediately after the first click on the assumption that the user is
  8. responding to the sound and should get the feedback of knowing that the computer knows
  9. s/he's now responding. SndStop1() is innocuous if in fact no sound is playing.
  10.  
  11. HISTORY:
  12. 4/30/88 dgp    wrote it
  13. 3/31/90    dgp    cleaned up code and documentation.
  14. 8/24/91    dgp    Made compatible with THINK C 5.0.
  15. 3/30/91    dgp    use SndStop1() instead of obsolete Sound Driver.
  16. 1/25/93 dgp removed obsolete support for THINK C 4.
  17. 4/29/95 dgp added GetNextEventOrQuit(), so that we can abort at any time by hitting Command-.
  18. 6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
  19. 6/6/96    dgp replaced US-only test by IsCmdPeriod() test, which will work internationally.
  20. 6/7/96  dhb use PrintfExit so it will work in a MEX file.
  21.         dhb fixed GetNextEventOrQuit so it compiles. It referenced an undefined variable.
  22. 2/3/97    dgp    added WaittNextEventOrQuit. Removed mention of "GetClicks: ", since
  23.             this may be called from other functions that are unrelated to GetClicks, e.g.
  24.             from WaitSecs() in TIMER.src.c in David's Psychophysics Toolbox
  25. 2/9/97    dgp    dropped need for IsCmdPeriod.c, but now require System 7.
  26. 3/10/97    dgp use the new CommandPeriod.c, which doesn't discard keyDown events.
  27. */
  28. #include "VideoToolbox.h"
  29. // GetNextEventOrQuit is in CommandPeriod.c
  30.  
  31. short GetClicks(void)
  32. {
  33.     long ticks;
  34.     EventRecord event;
  35.     short clicks;
  36.  
  37.     clicks=0;
  38.     while(!GetNextEventOrQuit(mDownMask,&event)) ;
  39.     SndStop1();    /* Stop sound on first click */
  40.     clicks++;
  41.     ticks=TickCount()+GetDblTime();
  42.     while(!GetNextEventOrQuit(mUpMask,&event)) ;
  43.     while(TickCount()<ticks){    /* wait as long as possible for another click */
  44.         if(GetNextEventOrQuit(mDownMask,&event)){
  45.             clicks++;
  46.             ticks=TickCount()+GetDblTime();
  47.             while(!GetNextEventOrQuit(mUpMask,&event)) ;
  48.         }
  49.     }
  50.     return clicks;
  51. }
  52.